import 'dart:convert';

import 'package:elevator/pages/login/login_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../utils/mynotification.dart';

class MyWebView extends StatefulWidget {
  const MyWebView({super.key});

  @override
  State<MyWebView> createState() => _MyWebViewState();
}

class _MyWebViewState extends State<MyWebView> {
  late final WebViewController controller;
  double height = 0;
  @override
  void initState() {
    controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..loadRequest(Uri.parse('https://www.baidu.com'));

    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        children: [
          ElevatedButton(onPressed: () => Future.delayed(const Duration(seconds: 1, ), () => common()), child: const Text('发送通知')),
          SizedBox(height:50,width:100,child: WebViewWidget(controller: controller,),),
          ElevatedButton(onPressed: () => Get.off(() => const LoginPage()), child: const Text('去登录页')),],
      ),
    );
  }

  common() async{

    //send 之前先判断权限
    // 某些权限不会显示要求用户允许或拒绝请求的权限的对话框。
    // 这是因为正在检索应用程序的操作系统设置以获得相应的权限。
    // 设置的状态将决定权限是granted还是denied。
    // 以下权限将不显示对话框：
    // 通知
    // 蓝牙
    // debugPrint("isGranted true");
    // //点击发送通知
    // Map params = {};
    // params['type'] = 200;
    // params['id'] = "10086";
    // params['content'] = "content";
    // notification.send("title", "content", params: json.encode(params));



    debugPrint("isGranted true");
    //点击发送通知
    Map params = {};
    params['type'] = 200;
    params['id'] = "100861";
    params['content'] = "content";
    notification.send("title", "content", params: json.encode(params));
  }

}

